/**
 * Copyright (c) 2018 软唐 All rights reserved.
 *
 * https://www.softtown.cn
 *
 * 版权所有，侵权必究！
 */

package com.softtown.modules.dapai.controller;

import com.github.pagehelper.PageInfo;
import com.softtown.common.exception.ErrorCode;
import com.softtown.common.regularUtils.RegularUtils;
import com.softtown.common.utils.Result;
import com.softtown.modules.dapai.dto.*;
import com.softtown.modules.dapai.entity.CompCustomerEntity;
import com.softtown.modules.dapai.entity.CompSaleOrderEntity;
import com.softtown.modules.dapai.service.CompCityService;
import com.softtown.modules.dapai.service.CompSaleOrderService;
import com.softtown.modules.dapai.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 销售订单管理
 *
 * @author Ding Ya Yong
 */
@RestController
@RequestMapping("saleOrder")
@Api(tags="销售订单管理")
public class CompSaleOrderController {



    @Resource
    private CompSaleOrderService compSaleOrderService;

    @PostMapping("getSaleOrderPageList")
    @ApiOperation("获取销售订单管理分页")
    public Result getSaleOrderPageList(@RequestBody CompSaleOrderPageDTO compSaleOrderPageDTO) {
        PageInfo<CompSaleOrderEntity> customerEntityPageInfo = compSaleOrderService.getSaleOrderPageList(compSaleOrderPageDTO);
        return new Result<PageInfo<CompSaleOrderEntity>>().ok(customerEntityPageInfo);
    }





    @PostMapping("getSaleOrderById")
    @ApiOperation("获取销售订单详情")
    public Result<CompSaleOrderVO> getSaleOrderById(@RequestBody CompSaleOrderPageDTO compSaleOrderPageDTO) {
        CompSaleOrderVO compSaleOrderVO = compSaleOrderService.getSaleOrderById(compSaleOrderPageDTO.getCompId(),compSaleOrderPageDTO.getId());
        return new Result<CompSaleOrderVO>().ok(compSaleOrderVO);
    }


    @PostMapping("addSaleOrder")
    @ApiOperation("添加销售订单")
    public Result addSaleOrder(@RequestBody SaleOrderAddOrUpdateDTO saleOrderAddOrUpdateDTO) {
        Result result = new Result<>();
        compSaleOrderService.addSaleOrder(saleOrderAddOrUpdateDTO);
        return result;
    }


    @PostMapping("updateSaleOrder")
    @ApiOperation("编辑销售订单")
    public Result updateSaleOrder(@RequestBody SaleOrderAddOrUpdateDTO saleOrderAddOrUpdateDTO) {
        Result result = new Result<>();
        compSaleOrderService.updateSaleOrder(saleOrderAddOrUpdateDTO);
        return result;
    }



    @PostMapping("deleteSaleOrder")
    @ApiOperation("删除销售订单")
    public Result deleteSaleOrder(@RequestBody CompSaleOrderPageDTO CompSaleOrderPageDTO) {
        Result result = new Result<>();
        compSaleOrderService.deleteSaleOrder(CompSaleOrderPageDTO.getCompId(),CompSaleOrderPageDTO.getId());
        return result;
    }





}